<?php
declare (strict_types = 1);

namespace app\model;

use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Model;

/**
 * 项目状态
 */
class Status extends Model
{
    /**
     * 创建项目状态
     *
     * @param [type] $data
     * @return array
     */
    public function createStatus($data): array
    {
        try {
            //检查是否存在重名
            if($this->where('name',$data['name'])->where('user_id',$data['user_id'])->find()){
                return modelResponse(403,'状态名重复');
            }
            $this->save($data);
            return modelResponse(200,'创建成功');
        }catch (\Exception $e){
            return modelResponse($e->getCode(),$e->getMessage());
        }
    }
    //创建状态类型枚举
    public function getTypeAttr($value): string
    {
        $type = [1=> '任务', 2=> '项目', 3=> '订单', 4=> '收支'];
        return $type[$value];
    }

}
